package codetop.microsoft.T718;

/**
 * @Author: 18362
 * @Create: 2022-09-07 10:52:37 星期三
 */
class Solution {
    public int findLength(int[] nums1, int[] nums2) {
        int[] dp = new int[nums1.length+1];
        int maxLen = 0;
        for (int i=0; i<nums2.length; ++i) {
            int last = dp[0];
            for (int j=1; j<dp.length; ++j) {
                if (nums1[j-1] != nums2[i]) {
                    last = dp[j];
                    dp[j] = 0;
                } else {
                    int temp = dp[j];
                    dp[j] = last + 1;
                    last = temp;
                }
                maxLen = Math.max(maxLen, dp[j]);
            }
        }
        return maxLen;
    }
}